Skip to content

feat(rocm): grouped + non-grouped keep-quant expert GEMM — the MoE-path terminus (issue #41) - #523

Draft
VikashLoomba wants to merge 2 commits into
mudler:mainfrom
VikashLoomba:row/ROCM-GG-ON-MOE
Draft

feat(rocm): grouped + non-grouped keep-quant expert GEMM — the MoE-path terminus (issue #41)#523
VikashLoomba wants to merge 2 commits into
mudler:mainfrom
VikashLoomba:row/ROCM-GG-ON-MOE

Conversation

@VikashLoomba

Copy link
Copy Markdown
Contributor

Row

BACKEND-ROCM — the last kernel blocker for MoE-bearing models on discrete ROCm. Issue #41. Stacked on #509 (MoE combine/gate chain).

What changed

NEW src/vt/rocm/rocm_grouped_gemm.hip — ports the keep-quant expert GEMM family from cuda_quant_dot.cu 1:1:

  • kMatmulBTQuant (op 74, non-grouped) + kMatmulBTQuantGrouped (op 75, grouped over expert_ids)
  • Q8_0 / Q4_K / Q5_K / Q6_K weight formats (the ones the target GDN-MoE GGUFs carry); Q8_0 + Q8_K activation quantizers
  • DotQ8_0/DotQ4K/DotQ5K/DotQ6K superblocks, __dp4a → portable Dp4a (bit-identical integer core), __shfl_down_sync reduction
  • Registering the non-grouped op is what flips GgufQuantComputeAvailable() on ROCm — the grouped op alone leaves the loader dequantizing experts to bf16.

Cross-device case: all four formats vs the CPU keep-quant oracle, valid random blocks + real activations.

Evidence (4× gfx1100, ROCm 7.14, Release)

  • grouped-quant case: 16/16 assertions across Q8_0/Q4_K/Q5_K/Q6_K, NMSE ≤ 5e-4 vs the CPU keep-quant reference
  • ctest -R 'rocm|cross_device': 4/4; full ctest: only the 5 pre-existing host/lane failures (zero new)
  • E2E: Qwen3.6-35B-A3B Q4_K_M (21GB GDN-MoE GGUF) runs end to end on one gfx1100 with keep-quant active — op 74 AND op 75 resolve vt-native, zero CPU-ref fallback, correct output. Requires --max-num-seqs 1 to fit one 24GB card (the GDN state pool otherwise pushes past — a residency note, not a kernel defect; confirmed via a backend-Alloc instrumentation run showing genuine cumulative ~23.8 GiB).
  • preflight --staged + trailers green

Speed claims

  • This PR makes NO speed claim.

Honest gaps

  • The K-quant formats Q2_K/Q3_K and the IQ2/IQ3 family are NOT ported (throw loudly); the target models don't use them. They follow the same skeleton.
  • The per-call hipMalloc/hipFree activation scratch is correctness-grade; a queue-owned grow-only pool is a perf lever (decode-step churn).
  • The 35B fits only with --max-num-seqs 1 on 24GB; multi-GPU expert sharding or host streaming is the follow-on for bigger MoE / longer context.

…mbineGate) (mudler#41)

The next links in the generic MoE path after the router/silu-mul. Hand-
translated from cuda_moe.cu (MoeCombineKernel :473, MoeCombineGateKernel :555)
and the SharedExpertGate CPU oracle (cpu_ops.cpp:2387). Grid-stride, f32 math,
bf16/f32 dtype arms via boundary conversions; the combine-gate folds the
shared-expert sigmoid gate rounded through bf16 exactly as the donor.

Evidence (4x gfx1100, ROCm 7.14, Release):
- new MoE combine/gate cross-device case: 9/9 assertions (MoeCombineGate's
  oracle is the host-computed composite — no CPU op registration exists)
- ctest -R 'rocm|cross_device': 4/4
- full ctest: pre-existing failure set shrinks 7 -> 5; test_bench and
  test_capi now PASS (they failed at op 77 / the router dtype before the
  chain). test_loaded_engine_dense now fails only on the async-scheduling
  assertion (a lane capability gap, not a kernel throw).
- Named remaining blocker: the grouped quant expert GEMM
  (kMatmulBTQuantGrouped), the DeepSeek-V4 keep-quant family.

FOLLOWING_AGENTS_PROTOCOL

Following-Agents-Protocol: true
AI-Assisted: true
Assisted-by: pi:kimi-k3 [pi]
…ant, kMatmulBTQuantGrouped) — the MoE-path terminus (mudler#41)

The last kernel blocker for GDN-MoE models on discrete ROCm. Ports the
cuda_quant_dot.cu grouped + plain keep-quant GEMMs (QuantDotGemmGroupedKernel
:746 / QuantDotGemmKernel :706 / the Q8_0 + Q8_K activation quantizers) and the
DotQ8_0 / DotQ4K / DotQ5K / DotQ6K superblocks 1:1. Registers kMatmulBTQuant
(op 74) + kMatmulBTQuantGrouped (op 75) — registering the non-grouped op flips
GgufQuantComputeAvailable() so the keep-quant path actually activates on ROCm.
Integer dot cores via a portable Dp4a (bit-identical to __dp4a); the HW dot
instruction is a named perf lever.

Evidence (4x gfx1100, ROCm 7.14, Release):
- cross-device grouped-quant case: 16/16 (Q8_0/Q4_K/Q5_K/Q6_K, valid random
  blocks + real f32 activations, NMSE <= 5e-4 vs the CPU keep-quant oracle)
- ctest -R 'rocm|cross_device': 4/4; full ctest: the 5 pre-existing
  host/lane failures only (test_bench + test_capi pass since the MoE chain).
- E2E: Qwen3.6-35B-A3B Q4_K_M (21GB GDN-MoE GGUF) runs end to end on one
  gfx1100 with keep-quant active — ops 74 AND 75 resolve vt-native, zero
  CPU-ref fallback, correct output. Needs --max-num-seqs 1 to fit one 24GB
  card (the GDN state pool otherwise pushes past; residency note, not a
  kernel defect). A backend-Alloc instrumentation run confirmed the OOM was
  cumulative ~23.8 GiB = genuine capacity, not a kernel bug.

FOLLOWING_AGENTS_PROTOCOL

Following-Agents-Protocol: true
AI-Assisted: true
Assisted-by: pi:kimi-k3 [pi]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant